package com.ambow.controller;

import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ambow.common.ResponseBean;
import com.ambow.pojo.SysUser;
import com.ambow.service.SysUserService;


/** 
* @author 黄广展
* @date 2018年9月8日 上午8:53:15
* @Description 
* @version V1.0
*/
@Controller
@RequestMapping("/user/")
public class SysUserController {
	@Resource(name="sysUserService")
	private SysUserService sysUserService;
	/**
	 * 根据id查询
	 * @param userId
	 * @return
	 */
	@RequestMapping("findById/{userId}")
	@ResponseBody
	 ResponseBean<SysUser> FindById(@PathVariable String userId){
		SysUser findById = sysUserService.findById(userId);
		return ResponseBean.createBySuccess("查询成功", findById);	
	}

	/**
	 * 查询所有
	 */
	@RequestMapping("findAll")
	@ResponseBody
	 ResponseBean<List<SysUser>> FindAll(){
		List<SysUser> findAll = sysUserService.findAll();
		return ResponseBean.createBySuccess("查询成功", findAll);	
	}
	/**
	 * 添加用户
	 * @return
	 */
	@RequestMapping("addSysUser")
	@ResponseBody
	 ResponseBean<Integer> AddSysUser(SysUser sysUser){
		 int i = sysUserService.add(sysUser);
		 if(i==0){
			 return ResponseBean.createByErrorMessage("添加失败"); 
		 }
		return ResponseBean.createBySuccess("查询成功", i);	
	}
	/**
	 * 更新用户
	 * @param userId
	 * @return
	 */
	@RequestMapping("updateSysUser/{userId}")
	@ResponseBody
	 ResponseBean<Integer> UpdateSysUser(@PathVariable String userId){
		 int i = sysUserService.update(userId);
		 if(i==0){
			 return ResponseBean.createByErrorMessage("更改失败"); 
		 }
		return ResponseBean.createBySuccess("更改成功", i);	
	}
	/**
	 * 
	 * @param sysUser
	 * @return
	 */
	@RequestMapping("deleteSysUser/{userId}")
	@ResponseBody
	 ResponseBean<Integer> DeleteSysUser(@PathVariable String userId){
		 int i = sysUserService.delete(userId);
		 if(i==0){
			 return ResponseBean.createByErrorMessage("删除失败"); 
		 }
		return ResponseBean.createBySuccess("删除成功", i);	
	}
}
